package org.springsource.batch;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.batch.item.ItemWriter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springsocial.domain.ExtendedTweet;
import org.springsocial.services.TweetService;


/**
 * Dummy {@link ItemWriter} which only logs data it receives.
 */
@Component("writer")
public class ExampleItemWriter implements ItemWriter<ExtendedTweet> {

	private static final Log log = LogFactory.getLog(ExampleItemWriter.class);
	@Autowired
	TweetService tweetService;
	/**
	 * @see ItemWriter#write(java.util.List)
	 */
	public void write(List<? extends ExtendedTweet> data) throws Exception {
		log.info(data);
		
		for (ExtendedTweet tweet : data) {
			tweetService.saveTweet(tweet);
		}

	}
	

}
